# -*- coding: utf-8 -*-
import math
import random

import Image
import ImageDraw
import ImageChops
import ImageFilter

def shrinkRect(rect, d = 1):
	(x, y), (w, h) = rect
	return (x + d, y + d), (w - d, h - d)

def border(image):
	draw = ImageDraw.Draw(image)
	w, h = image.size
	rect = ((0,0), (w - 1, h - 1))
	draw.rectangle(rect, outline = (128, 128, 128, 0))
	rect = shrinkRect(rect)
	draw.rectangle(rect, outline = (0, 0, 0, 255))	
	return image

def pageBend(image):
	pixels = image.load()
	width, height = image.size
	# w = width * 0.1
	w = 32
	d = (math.pi / 2) / (w)
	s = 0
	for x in xrange(width - int(w), width):
		m = math.cos(s)
		for y in xrange(height):
			pixels[x, y] = tuple(int(m * p) for p in pixels[x, y])
		s += d
	return image

def shadow(image):
	pixels = image.load()
	width, height = image.size
	w = 32
	d = ((math.pi / 2) / (w))
	s = 0
	for x in xrange(w):
		m = math.sin(s)
		for y in xrange(height):
			pixels[x, y] = tuple(int(m * p) for p in pixels[x, y])
		s += d

	s = 0
	for y in xrange(w):
		m = math.sin(s)
		for x in xrange(width):
			pixels[x, y] = tuple(int(m * p) for p in pixels[x, y])
		s += d
	return image

